home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6397 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP: UNIX's directory functions.
  5. Date: Sat, 24 Feb 96 14:32:30 GMT
  6. Organization: none
  7. Message-ID: <825172350snz@genesis.demon.co.uk>
  8. References: <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu> <824598921snz@genesis.demon.co.uk> <4gigogINN8nq@keats.ugrad.cs.ubc.ca> <4gj6ug$o0h@news-f.iadfw.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4gj6ug$o0h@news-f.iadfw.net>
  15.            alpet@airmail.net "Adam Peterson" writes:
  16.  
  17. >c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
  18. >
  19. >>In article <824598921snz@genesis.demon.co.uk>,
  20. >>Lawrence Kirby  <fred@genesis.demon.co.uk> wrote:
  21. >> >In article <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu>
  22. >> >           dxp8108@hertz.njit.edu "Dharmesh Patel" writes:
  23. >> >
  24. >> >>
  25. >> >>Hi all!
  26. >> >>
  27. >> >>I need help with couple of things in C.  I need to know how the functions 
  28. >> >>opendir, readdir, closedir, and rewinddir work.  I also need to know the 
  29. >> >>elements of the struct dirent.
  30. >> >
  31. >> >Unfortunately these are not defined in C. 
  32. >> >
  33. >> >>The reason for this request is that I have to write a program that 
  34. >> >>simulates the unix command 'pwd', the hard way.
  35. >> >
  36. >> >They are Unix/POSIX defined functions and the place to ask about them
  37. >> >is comp.unix.programmer.
  38. >
  39. >>...and I might add that the revered "K&R" book does cover the basic UNIX
  40. >>programming interface, including directory functions, stat() and other
  41. > goodies.
  42. >
  43. >>It sounds like you don't have this book. Shame! :)
  44.  
  45. My copy of K&R2 has a chapter on "The UNIX System Interface". The first
  46. paragraph makes the purpose of this chapter clear and the fact that it does
  47. not describe standard C functions. Schildt mingles DOS specific calls with
  48. standard C calls in his books. That does not mean that DOS specific calls
  49. are part of C. While K&R2 is a more reliable reference it no more defines
  50. ANSI C than do Schildt's books (at least the bits of them that Schildt
  51. wrote).
  52.  
  53. >To answer the original question, Unix treats directories like files,
  54. >thus the open, read, close, rewind functions.  To process a list of
  55. >files do something like this:
  56. >
  57. >if opendir succeeds
  58. >{
  59. >  while not eof dir
  60. >    readdir
  61. >  closedir
  62. >}
  63.  
  64. I don't see you using "the open, read, close, rewind functions" there! :-)
  65. (The point is that opendir etc. almost certainly use open etc. but present
  66. the data in a portable format).
  67.  
  68. -- 
  69. -----------------------------------------
  70. Lawrence Kirby | fred@genesis.demon.co.uk
  71. Wilts, England | 70734.126@compuserve.com
  72. -----------------------------------------
  73.